# -*- coding: utf-8 -*-

'''eof
name:借款人被纳入失信被执行人
code:R51_IG_CASE_PersonalLostLetterRecordCheck_WHB
tableName:
columnName:
groups:强规则>司法信息校验
dependencies:EG_CASE_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
import pandas as pd
import json
from datetime import datetime


def FormatData(tableName):
    try:
        eg = EG_CASE_DSJ.get("data").get(tableName)
        return eg if isinstance(eg, list) else [{}]
    except:
        return [{}]


def get_shixin_or_zhixing_count(*args):
    shixin_list = FormatData(args[0])
    if shixin_list == [{}]:
        return u'缺失值'
    else:
        if len(shixin_list) >= 1:
            duplicate_list = []
            flag = False
            for i in shixin_list:
                casecode = i.get(args[1])
                if casecode not in null_type_list and casecode not in duplicate_list:
                    flag = True
                    duplicate_list.append(casecode)
            return len(duplicate_list) if flag else u'缺失值'
        else:
            return 0


null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']


def getRule51():
    zhixing_count = get_shixin_or_zhixing_count(*("R231", "CASECODE"))
    return zhixing_count


if __name__ == "__main__":
    file_obj = open(r'../data/rating/R51_IG_CASE_PersonalLostLetterRecordCheck/EG_CASE_DSJ.json', 'r')
    content = file_obj.read()
    EG_CASE_DSJ = json.loads(content, strict=False)
    aa = getRule51()
    print aa

result = getRule51()
